<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Auth;
use Latrell\Geohash\Facades\Geohash;
use Illuminate\Support\Facades\Hash;

/**
 * 用户
 *
 * @author Miluo Huang
 *
 * @SWG\Model(id="Member")
 */
class Member extends Model implements AuthenticatableContract
{
	use Authenticatable, SoftDeletes ;

	protected $table = 'members';

    static $status = [
        1 => '允许登陆',
        0 => '禁止登陆',
    ];

    static $sex = [
        1 => '男',
        2 => '女'
    ];

	public static function boot()
	{
		parent::boot();

		static::saving(function ($model)
		{
			// 保存的时候自动对密码进行加密。
			if (isset($model->password) && Hash::needsRehash($model->password)) {
				$model->password = Hash::make($model->password);
			}
		});
	}

	/**
	 * 头像
	 */
	public function avatar()
	{
		return $this->belongsTo('App\Models\UserFile', 'avatar_id');
	}

    /**
     * 获取订单假数据
     */
    public function getApplyFalseDataAttribute(){
        $data = \DB::select("select * from member_false_datas where member_id = {$this->id} limit 1");
        $data = empty($data) ? null : $data[0];

        return (array)$data;
    }

}
